package com.ruoyi.mining.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
//import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.mining.domain.Exam;
import com.ruoyi.mining.service.IExamService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 小升初考试登记Controller
 *
 * @author mining
 * @date 2025-05-23
 */
@Api(value = "小升初报考记录", tags = "小升初报考记录Controller")
@RestController
@RequestMapping("/exam")
public class ExamController extends BaseController {
    @Autowired
    private IExamService examService;

    /**
     * 查询小升初考试登记列表
     */
//    @RequiresPermissions("mining:exam:list")
    @GetMapping("/list")
    public TableDataInfo list(Exam exam) {
        startPage();
        List<Exam> list = examService.selectExamList(exam);
        return getDataTable(list);
    }

    /**
     * 导出小升初考试登记列表
     */
//    @RequiresPermissions("mining:exam:export")
    @Log(title = "小升初考试登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Exam exam) {
        List<Exam> list = examService.selectExamList(exam);
        ExcelUtil<Exam> util = new ExcelUtil<Exam>(Exam.class);
        util.exportExcel(response, list, "小升初考试登记数据");
    }

    /**
     * 获取小升初考试登记详细信息
     */
//    @RequiresPermissions("mining:exam:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(examService.selectExamById(id));
    }




    @ApiOperation("根据申请学校和学生的身份证号码查询报考信息")
    @GetMapping("/queryExamByApplySchoolAndIdcard")
    public AjaxResult queryExamByApplySchoolAndIdcard(@ApiParam(value = "学生报考学校", required = true) @RequestParam(value = "applySchool") String applySchool ,
                                                      @ApiParam(value = "学生身份证号码", required = true) @RequestParam(value = "idCard") String idCard
                                                      ) {
        return success(examService.queryExamByApplySchoolAndIdcard(applySchool , idCard));
    }





    /**
     * 修改小升初考试登记
     */
//    @RequiresPermissions("mining:exam:edit")
    @Log(title = "小升初考试登记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Exam exam) {
        try {
            return success(examService.updateExam(exam));
        }catch (Exception e){
            return error("修改错误");
        }

    }

    /**
     * 删除小升初考试登记
     */
//    @RequiresPermissions("mining:exam:remove")
    @Log(title = "小升初考试登记", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(examService.deleteExamByIds(ids));
    }
}
